﻿using System;
using System.Text;
using System.Data;

namespace LKCMS.Web
{
    public partial class Links : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            BindLink();
        }

        private void BindLink()
        {
            StringBuilder sb = new StringBuilder();
            LKCMS.BLL.Links bll = new LKCMS.BLL.Links();
            DataTable dt = bll.GetList(" IsRed=1 and IsLock=0 ").Tables[0];
            int n = dt.Rows.Count/8;
            int m=dt.Rows.Count%8;
            int t=8-m;
            if(n<1)
            {
               sb.Append("<tr class=white03>");
                for (int j = 0; j < 8; j++)
                { 
                    if(j<m)
                    {
                        sb.Append("<td class=white03 align=left>. <a href=" + dt.Rows[j]["WebUrl"].ToString() + " target=_blank title=\""+dt.Rows[j]["Title"].ToString()+"\">"+dt.Rows[j]["Title"].ToString()+"</a></td>");
                    }
                    else
                    {
                      sb.Append("<td class=white03 align=left>. <a href=# target=_blank title=\"暂无\">暂无</a></td>");
                    }

                }

                sb.Append("</tr>");
            }
            else
            {

            for (int i = 0; i < n; i++)
            {
                sb.Append("<tr class=white03>");
                for (int j = 0 + 8 * n; j < 8 + 8 * n; j++)
                { 
                    if(j<m+8*n)
                    {
                        sb.Append("<td class=white03 align=left>. <a href=" + dt.Rows[j + 8 * n]["WebUrl"].ToString() + " target=_blank title=\"" + dt.Rows[j + 8 * n]["Title"].ToString() + "\">" + dt.Rows[j+8*n]["Title"].ToString() + "</a></td>");
                    }
                    else
                    {
                      sb.Append("<td class=white03 align=left>. <a href=# target=_blank title=\"暂无\">暂无</a></td>");
                    }

                }
                sb.Append("</tr>");
            }

            }

            this.LiteralLinks.Text = sb.ToString();
        }
    }
}